(in-package :gwee)

(defclass animation-mixin ()
  ((interval :initform nil :accessor animation-interval)
   (last-update :initform nil :accessor animation-last-update)
   (update-callback :initform nil :initarg :update-callback :accessor update-callback)))

(defgeneric update-animation (animation))

(defmethod shared-initialize :after ((obj animation-mixin) slots &key (fps nil supplied-p))
  (when (and supplied-p
             (not (animation-interval obj)))
    (setf (animation-interval obj) (truncate (* (/ 1 fps) internal-time-units-per-second)))))

(defmethod update-animation ((obj animation-mixin))
  (when (u:funcallable (update-callback obj))
    (funcall (update-callback obj) obj)
    (setf (view-needs-update-p obj) t)))

